//
//  BindingCardViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/31.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "BindingCardViewController.h"
#import "WebViewController.h"//网页Controller

@interface BindingCardViewController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *bankName;
@property (weak, nonatomic) IBOutlet UITextField *cardNum;

@end

@implementation BindingCardViewController
{
    NSString *_number;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationController.navigationBar.hidden = YES;
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}

- (IBAction)commit:(id)sender {
    if ([_userName.text isEqualToString:@""]) {
        [EBUtility prompt:@"请输入持卡人姓名" with:self];
    }else if ([_bankName.text isEqualToString:@""]){
        [EBUtility prompt:@"请输入开户行全称" with:self];
    }else if ([_cardNum.text isEqualToString:@""]){
        [EBUtility prompt:@"请输入银行账号" with:self];
    }else{
        [SVProgressHUD show];
        [SVProgressHUD showSuccessWithStatus:@"绑定成功"];
        _bindingSucceed(_bankName.text, _cardNum.text);
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            [self.navigationController popViewControllerAnimated:YES];
        });
    }
}

#pragma mark === UITextFieldDelegate ===
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == _cardNum) {
        if (textField.text.length == 6) {
            textField.text = [NSString stringWithFormat:@"%@ ", textField.text];
        }else if (textField.text.length == 16){
            textField.text = [NSString stringWithFormat:@"%@ ", textField.text];
        }else if (textField.text.length > 20){
            return NO;
        }
    }
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [_userName resignFirstResponder];
    [_bankName resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_userName resignFirstResponder];
    [_bankName resignFirstResponder];
    [_cardNum resignFirstResponder];
}
/**绑定说明*/
- (IBAction)bindingIntroduction:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"绑定说明";
    [self presentViewController:web animated:YES completion:nil];
}
- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
